<%@ page import="java.util.ArrayList,
                 ro.xblue.translator.LanguageBean,
                 ro.xblue.translator.TranslatorUtils,
                 ro.gateway.aida.obj.AIDADocument"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %><head>
<trans:initPage module="act_stuff" />

<html:html>
<head>
      <link rel="stylesheet" href="<html:rewrite page="/alf.css" />" type="text/css">
      <script language="javascript">
            function make_layer_visible(layer) {
                  layer = document.getElementById(layer);
                  if (!layer) return;

                  if (layer.style) {
                        layer.style['visibility'] = 'visible';
                  } else {
                        layer.visibility = 'visible';
                  }
            }

            function cancel_create(forma) {
                  forma.action.value = 'cancel_create';
                  var els = forma.elements;
                  for (var i = 0; i < els.length; i++) {
                        if (els[i].name && (els[i].name.indexOf('xfile') != -1)) {
                              els[i].value = ''; // not working? :-?
                        }
                  }
                  forma.submit();
            }
      </script>
</head>
<body bgcolor="#FFFFFF" text="#000000">

<div id="loading" style="position: relative;visibility: hidden;height:50px;width:50%;left: 25%;top:5%;text-align: center;vertical-align: middle;border: 1px dotted;background-color: #f2f2f2;" class="text_searchbold"> 
  <br>
  Loading...<br>
  Please wait<br>
</div>
      <logic:equal value="create" parameter="action">
      <form action="<%=request.getContextPath()%>/activity/doc_upload" method="post"
      enctype="multipart/form-data">
      </logic:equal>
      <logic:notEqual value="create" parameter="action">
      <form action="<%=request.getContextPath()%>/activity/edit_files.do" method="post">
      </logic:notEqual>
      <table width="90%" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#3399CC" class="text_searchbold">
            <tr bgcolor="#3399CC" class="textalb">
                  <td colspan="2">
                  <trans:showPageMessage label="files.title" />
                  </td>
            </tr>

            <tr bgcolor="#FFFFFF">
                  <td colspan="2">&nbsp;
                  
                  </td>
            </tr>

            <%
                  LanguageBean lang = TranslatorUtils.getCurrentLanguage(request, application);
                  ArrayList items = ( ArrayList ) request.getAttribute("files_items");
                  int[] idxs = ( int[] ) request.getAttribute("files_idxs");
            %>
            <% for ( int i = 0; i < idxs.length; i++ ) { %>
                  <%
                  AIDADocument document = ( AIDADocument ) items.get(idxs[i]);
                  %>
                  <% if (i > 0) { %>
                        <tr>
                              <td colspan="2">
                              <hr size="1"/>
                              </td>
                        </tr>
                  <% } %>
                  <tr bgcolor="#FFFFFF">
                        <td align="right"><trans:showPageMessage label="act_stuff.title" />: </td>
                        <td>
                              <input type="text" name="title<%=idxs[i]%>" size="35" value="<%=document.getTitle(lang.language) != null ? document.getTitle(lang.language) : ""%>"/>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td align="right"><trans:showPageMessage label="act_stuff.desc" />: </td>
                        <td>
                              <textarea rows="3" cols="45" name="description<%=idxs[i]%>"><%=document.getDesc(lang.language) != null ? document.getDesc(lang.language) : ""%></textarea>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td align="right"><trans:showPageMessage label="act_stuff.file" />: </td>
                        <td align="left">
                              <logic:equal value="create" parameter="action">
                                    <input type="file" name="xfile<%=idxs[i]%>" />
                              </logic:equal>
                              <logic:notEqual value="create" parameter="action">
                                    <%=document.getRelativeLink()%>
                              </logic:notEqual>
                        </td>
                  </tr>
            <% } %>

            <script language="javascript">
                  function save(forma) {
                        var els = forma.elements;
                        for (var i = 0; i < els.length; i++) {
                              if (els[i].name.indexOf('description') != -1) {
                                    if (!els[i].value || (els[i].value.length==0)) {
                                          els[i].focus();
                                          alert('Enter the description here!');
                                          return;
                                    }
                              } else if (els[i].name.indexOf('title') != -1) {
                                    if (!els[i].value || (els[i].value.length==0)) {
                                          els[i].focus();
                                          alert('Enter the title here!');
                                          return;
                                    }
                              }
                        }
                        forma.action.value='save';
                        forma.submit();
                  }
            </script>
            <!-- submitari -->
            <tr bgcolor="#f9f9f9">
                  <td align="center" bgcolor="f9f9f9" colspan="2">
                  <input type="hidden" name="action" value="" />
                  <input type="hidden" name="idxs" value="<%=request.getAttribute("idxs")%>" />
                  <input type="hidden" name="key" value="<%=request.getParameter("key")%>" />
                  <input type="button"
                        class="butonsave"
                        onclick="javascript:save(this.form);"
                        value="<trans:showPageMessage label="files.save" hide_link="true" />" />
                  <logic:equal value="create" parameter="action">
                        <input type="button" value="<trans:showPageMessage label="act_stuff.cancel" hide_link="true" />" name="x22"
                        onClick="javascript:cancel_create(this.form);"
                        class="butonsave" />
                  </logic:equal>
                  <logic:notEqual value="create"  parameter="action" >
                        <input type="button" value="<trans:showPageMessage label="act_stuff.cancel" hide_link="true" />"
                        onClick="javascript:window.close();"
                        class="butonsave" />
                  </logic:notEqual>
                  </td><trans:showPageMessage label="translator.showhiddentags"/>
            </tr>
      </table>
      </form>
</body>
</html:html>
